package com.example.hangzhou.welbeing.mytestdemoapp.mvp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.example.hangzhou.welbeing.mytestdemoapp.R;
import com.example.hangzhou.welbeing.mytestdemoapp.mvp.personter.WowSplashPersenter;
import com.example.hangzhou.welbeing.mytestdemoapp.mvp.view.ISWowSplashView;
import com.example.hangzhou.welbeing.mytestdemoapp.mvp.view.WowSplashView;
import com.example.hangzhou.welbeing.mytestdemoapp.mvp.view.WowView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 杭州惟君医疗科技有限公司14
 * Created by 20433 on 2018/5/3
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class WowSplashActivity extends AppCompatActivity implements ISWowSplashView {

    @Bind(R.id.activity_wow_splash_mvp_wow_splash)
    WowSplashView activityWowSplashMvpWowSplash;
    @Bind(R.id.activity_wow_splash_mvp_wowview)
    WowView activityWowSplashMvpWowview;
    private Handler mHandler = new Handler();
    private WowSplashPersenter mWowSplashPersenter = new WowSplashPersenter(this);
    private Activity myActivity;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wow_splash);
        ButterKnife.bind(this);

    }

    @Override
    protected void onStart() {
        super.onStart();
        activityWowSplashMvpWowSplash.startAnimate();
        boolean isflag = mWowSplashPersenter.getISGuideFigure(this);
        boolean islogin = mWowSplashPersenter.getISLogin(this);
        activityWowSplashMvpWowSplash.setOnEndListener(new WowSplashView.OnEndListener() {
            @Override
            public void onEnd(WowSplashView wowSplashView) {
                pagerJomp(isflag, islogin);
            }
        });
    }

    private void pagerJomp(final boolean isflag, final boolean islogin) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isflag) {
                    if (islogin) {
                        mWowSplashPersenter.toMain();
                    } else {
                        mWowSplashPersenter.toLogin();
                    }
                } else {
                    mWowSplashPersenter.toGuideFigure();
                }
            }
        }, 10);
    }

    @Override
    public void toMainActivityPager() {
        Intent intent = new Intent(WowSplashActivity.this, MyMainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    public void toGuideFigureActivityPager() {
        Intent intent = new Intent(WowSplashActivity.this, guideFigureActivity.class);
        startActivity(intent);
    }

    @Override
    public void toLoginActivityPager() {
        Intent intent = new Intent(WowSplashActivity.this, MyLoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
    }

    @Override
    public void showToastInfo(String info) {
        Toast.makeText(WowSplashActivity.this, info, Toast.LENGTH_SHORT).show();
    }
}
